package September20;

import java.util.Scanner;
import java.util.regex.Pattern;

public class RemoveNonChinese {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String input = scanner.nextLine();
        String result = removeNonChinese(input);
        System.out.println("只包含汉字的字符串是: " + result);
        scanner.close();
    }

    public static String removeNonChinese(String input) {
        // 使用正则表达式替换非汉字字符为空字符串
        return input.replaceAll("[^\\u4e00-\\u9fa5]", "");
    }
}
